﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using QuickGame.View;

namespace QuickGame.Model
{
    public class CauHoiHs
    {
        public static IQueryable<CauHoi> QueryEntities(ModelContext modelContext)
        {
            return modelContext.CauHois;
        }

        public static CauHoi QueryEntity(ModelContext modelContext, long id)
        {
            return modelContext.CauHois.Single(k => k.ID == id);
        }

        public static CauHoi Insert(ModelContext modelContext)
        {
            CauHoi ch = new CauHoi();
            modelContext.CauHois.AddObject(ch);
            return ch;
        }
        public static void Delete(ModelContext modelContext, long id)
        {
            CauHoi ch = modelContext.CauHois.Single(k => k.ID == id);
            foreach (var cautraloi in ch.CauTraLois)
            {
                modelContext.CauTraLois.DeleteObject(cautraloi);
            }
            modelContext.CauHois.DeleteObject(ch);
        }
        public static void Update(ModelContext modelContext, CauHoiView view)
        {
            CauHoi ch = modelContext.CauHois.Single(k => k.ID == view.ID);
            ch.ID = view.ID;
            ch.Ma = view.Ma;
            ch.Ten = view.Ten;
            ch.IDLoai = view.Loai;
            ch.IDCapDo = view.CapDo;
            modelContext.SaveChanges();
        }
    }
}